package gnss

import "fmt"

type GnssSVSignal struct {
	NaviSys byte
	SatId   uint16 // 可能会超过255, rangecmp中定义ushort
	SigId   byte
	SigCode string

	PsV     float64
	PhV     float64 // 相位 周数
	Doppler float64 // 瞬时多普勒，Hz
	Cnr     float32
	LkT     int64 // ms
	LLI     byte  // 失锁   1:失锁
	HalfAmb byte
}

func (this *GnssSVSignal) Reset() {
	this.SigCode = ""
	this.PsV = 0
	this.PhV = 0
	this.Doppler = 0
	this.Cnr = 0
	this.SatId = 0
	this.SigId = 0
	this.LLI = 0
}

func (this *GnssSVSignal) IsValid() bool {
	return this.PsV != 0 && this.PhV != 0
}

func (this *GnssSVSignal) GetRnxLLI() byte {
	v := U8_0
	if this.LLI == 1 {
		v = v | 1
	}
	if this.HalfAmb == 1 {
		v = v | (1 << 1)
	}
	return v
}

func (this *GnssSVSignal) GetRnxLLIStr() string {
	v := this.GetRnxLLI()
	if v == 0 {
		return " "
	} else {
		return fmt.Sprintf("%d", v)
	}
}

func (this *GnssSVSignal) GetSignalCode() string {
	if len(this.SigCode) > 0 {
		return this.SigCode
	}

	str := GnssSvSigId2Code(this.NaviSys, this.SigId)
	if str == "" {
		return ""
	}
	this.SigCode = str
	return this.SigCode
}

func (this *GnssSVSignal) GetPrnCode() string {
	return GetGnssSvPrnCode(this.NaviSys, this.SatId)
}

//func (this *GnssSVSignal) GetSignType() byte {
//	return YObsSigId2SigType(this.NaviSys, this.SigId)
//}
